﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using ProduceBasicData.Api.Application.Command.ProductionManage.Repost;
using ProduceBasicData.Api.DTO.ProductionManage;
using ProduceBasicData.ErrorCode;

namespace ProduceBasicData.Api.Controllers.Report
{
    /// <summary>
    /// 报工相关控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ReportController : ControllerBase
    {
        private readonly IMediator mediator;

        public ReportController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 下发报工
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> CreateReport(CreateReportCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 审批报工
        /// </summary>
        /// <param name="request">命令</param>
        /// <returns>返回任务</returns>
        [HttpPost]
        public async Task<ApiResult<int>> UpdateReport(ApproveReportCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取所有报工记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<ShowReportdto>> GetReport([FromQuery]GetReportCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 审核人才可以看到报工
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiPaging<ShowReportdto>> Mypaping([FromQuery]MyPapingCommand request)
        {
            return mediator.Send(request);
        }
    }
}
